/*
 *  timer.c
 *  Sandbox
 *
 *  Created by Joshua Lewis on 10/28/10.
 *  Helper functions to accurately time algorithm execution.
 *
 */

#include "timer.h"

static mach_timebase_info_data_t sTimebaseInfo;

void startTimer(){
	timerStart=mach_absolute_time();
}

double stopTimer(){
	uint64_t timerEnd;
	uint64_t elapsed;
	double elapsedSeconds;
	
	timerEnd=mach_absolute_time();
	elapsed=timerEnd-timerStart;
	
	if ( sTimebaseInfo.denom == 0 ) {
    (void) mach_timebase_info(&sTimebaseInfo);
  }
	
	elapsedSeconds = 1e-09 * (double)(elapsed * sTimebaseInfo.numer / (sTimebaseInfo.denom));
	return elapsedSeconds;
}
